'''
Created on Apr 24, 2012

@author: mekoda
'''
import unittest
from main.cpu import CPU
from main.process import PCB, Instruction, Process, IOInstruction,ProcessStatus
from main.shortTermSchedulers import Scheduler_ShortestJobFirst_NE
from main.ioDevs import IO
from main.dataStructures import ProcessesQueue
from main.memory import MMU_ContinuousAssignment,BestAdjustment,PhysicalMemory

class TestPlanners(unittest.TestCase):
    def setUp(self):
        self.memory = PhysicalMemory(5,BestAdjustment())
        self.mmu = MMU_ContinuousAssignment()
        self.ioQueue = IO()
        self.pcb1 =  PCB(3)
        self.pcb2 =  PCB(6)
        self.pcb3 =  PCB(7)
        self.instruction1 =  IOInstruction(1,'Printer')
        self.instruction2 =  Instruction(ProcessStatus().CPU,1)
        self.instruction3 =  IOInstruction(1,'Printer')
        self.instruction4 =  IOInstruction(1,'Printer')                  #tiempo en que se ejecutara el Proceso1: 4
        self.instruction5 =  Instruction(ProcessStatus().CPU,5)
        self.instruction6 =  IOInstruction(1,'Printer')
        self.instruction7 =  Instruction(ProcessStatus().CPU,3)          #tiempo en que se ejecutara el Proceso2: 9
        self.instruction8 =  Instruction(ProcessStatus().CPU,8)
        self.instruction9 =  IOInstruction(6,'Printer')
        self.instruction10=  Instruction(ProcessStatus().CPU,12)         #tiempo en que se ejecutara el Proceso3: 16
        #------------------------------------------#
        self.process1 = Process(self.pcb1)
        self.process1.addInstruction(self.instruction1)
        self.process1.addInstruction(self.instruction2)
        self.process1.addInstruction(self.instruction3)
        self.process1.addInstruction(self.instruction4)
        #------------------------------------------#
        self.process2 = Process(self.pcb2)
        self.process2.addInstruction(self.instruction5)
        self.process2.addInstruction(self.instruction6)
        self.process2.addInstruction(self.instruction7)
        #------------------------------------------#
        self.process3 = Process(self.pcb3)
        self.process3.addInstruction(self.instruction8)
        self.process3.addInstruction(self.instruction9)
        self.process3.addInstruction(self.instruction10)
        self.process = ProcessesQueue()
        self.process.append(self.process1)
        self.process.append(self.process2)
        self.process.append(self.process3)
        self.cpu = CPU(self.process,self.ioQueue,self.mmu,self.memory)
        
#--------------------------------------------------------------------------#
#------------------TESTING: Scheduler_ByPriorities-------------------------#
#--------------------------------------------------------------------------#
    def setUp_Scheduler_ShortestJobFirst_NE(self):
        self.planner = Scheduler_ShortestJobFirst_NE(self.process,self.cpu,self.ioQueue)        
        
        
    #Toma el proceso mas corto de todos    
    def test_GetTheShortestProcess(self):
        self.setUp_Scheduler_ShortestJobFirst_NE()
        self.planner.manageAProcess()                           #Toma al proceso ,cuya suma de tiempo de sus instrucciones es el menor de entre los procesos y sus tiempos
        self.assertEquals(self.process1,self.cpu.currentProcess)#El proceso elegido es el 1
     
    
    
suite = unittest.TestLoader().loadTestsFromTestCase(TestPlanners)
unittest.TextTestRunner(verbosity=2).run(suite)